package logic

import (
	"context"
	"errors"
	"pro/models/mysql"

	"pro/prorpc/internal/svc"
	"pro/prorpc/prorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoctorShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorShowLogic {
	return &DoctorShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DoctorShowLogic) DoctorShow(in *prorpc.DoctorShowRequest) (*prorpc.DoctorShowResponse, error) {
	// todo: add your logic here and delete this line

	var doctor mysql.Doctor
	mysql.DB.Debug().Where("id=?", in.DoctorId).Find(&doctor)
	if doctor.ID == 0 {
		return nil, errors.New("当前患者不存在")
	}

	return &prorpc.DoctorShowResponse{
		HeadImage: doctor.HeadImage,
		Name:      doctor.Name,
		Tel:       doctor.Tel,
		Ke:        doctor.Ke,
		Price:     float32(doctor.Price),
		DoctorId:  int64(doctor.ID),
	}, nil
}
